home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
CC_C
/
0924.ZIP
/
SHELPC
< prev
next >
Wrap
Text File
|
1988-01-10
|
14KB
|
345 lines
/* FILE SHELPC
SMC by TJMC
(Version 2.2 created 10.1.88)
-----------------------------
General
-------
SMC is a version of the C Programming Language. The major differences
between SMC and the Kernighan and Ritchie C specification are:
- The entire program is compiled as one complete source file, which is
compiled directly (in one pass) to an executable object code file;
- Certain data types (long and double) are not implemented;
- Arrays must be 1-dimensional only.
Command Line
------------
SMC SCEFILE OBJFILE -B -F -L -N -R -Dxx -Sxx \n
Options: no Bell on error, no Float arithmetic, no compilation Listing,
function Names embedded inline, functions Report list,
set Data size (in kbytes), set Stack size (in kbytes).
Example: SMC TCED EDIT.COM -fld62s1 <Return>, to compile the
editor TCED (which has no floats), with no listing,
62k data area and 1k stack - as it should have.
Differences from the Kernighan
and Ritchie specification:
------------------------------
1. SMC was implemented, in SMC source code, on the Amstrad
PC1512 computer operating under MSDOS. It will run on any
8086/8088 computer operating MSDOS Version 3, with 256k memory.
2.2 The first 8 characters of an identifier are significant.
2.3 Keyword 'entry' is not implemented.
2.4 Octal digits 8 and 9, and long and double constants are not
implemented, and will produce errors.
2.6 Char variables are 8 bits, and int and unsigned int are 16 bits.
Long int and short int are equivalent to int. Long float and
double are equivalent to float. Float variables are 48 bits,
the first 16 bit word as sign and exponent (unit value 0x200),
then a two word mantissa, the more significant first. This
gives accuracy to 9 sig figs, and range 1. E +/- 150.
4. 'Register' is not acted on, except to define storage. Local
declarations may only be made at the head of a function body,
not at the head of any compound statement.
6.1 Char variables are not sign extended on conversion to int.
6.2 All float arithmetic is carried out to single float precision.
6.6 Conversions apply as stated, but only for char, int, unsigned
and (single precision) float.
7. Expressions are evaluated according to the stated precedence and
associativity - but if not stated, left to right. Arithmetic
overflow and division by 0 are both ignored.
7.1 Function arguments are evaluated and stacked left to right.
Float arguments are not converted to double.
7.2 Sizeof is permitted only on type-names, identifier names or
structure.elements - not on expressions generally.
7.3 The remainder of a division has the same sign as the dividend.
7.5 Shifts by negative values are undefined. Right shifts of an int
are arithmetical, with sign extension.
7.7 The null pointer is actually valued 0, which is not a valid address.
8.1 'Register' has no effect, except to define storage. An identifier
(other than a function) declared extern must already be defined.
8.2 Long int and short int are equivalent to int. Long float and
double are taken as float.
8.4 Multi-dimensional arrays are not implemented, nor pointers to
specified-size arrays (eg (*a)[4]). Unspecified-size arrays are
converted to pointers, except where they reserve storage - so:
int (*a)[]; converts to int **a;
int a[] = { 1, 2 }; gives a 2-element array;
int a[]; gives an error.
However, the array subscript operator may be used multi-
dimensionally, eg. on an array of pointers to char.
8.5 Fields are not implemented.
8.6 Automatic variables may not be initialised. Within a struct, char
arrays may not be initialised by strings. Floats may be initialised
conventionally, or as if they were the following struct:
struct { int exponent, MS_mantissa, LS_mantissa; }
eg. float ten = { 0x204, 0xA000, 0 }; (instead of 10.)
9.2 Declarations are permitted at the head of a function body only - not
at the head of any compound statement.
9.7 Switch statements must be compound.
9.new The statement inline (k1, k2, ..... kn); compiles constant values
k1 to kn into the object code. If any constant is less than 0x100
it is compiled as a single byte, else it is compiled as a word. All
addresses (of static variables and strings) exceed 0x100.
10.new Functions may be declared variadic by preceding their definition
with type fn-dec() auto; when the address of the first (left hand)
argument (as pushed on the stack at run time) will be pushed as an
additional last argument. The function will then see, as the value
of its first argument, the address of the top of the argument list.
Functions printf(), fprintf(), sprintf(), scanf(), fscanf() and
sscanf() are automatically compiled as variadic.
11. The whole program must be compiled as one source file, with all
references resolved, if necessary using #include files. Static
global variables are visible throughout the entire source program.
Extern variables must have been defined before declaration.
11.1 Typedef names are in a disjoint class to ordinary identifiers.
12.1 Macros may not have arguments. #undef is not implemented.
12.2 #include control lines may be:
#include filename
#include "filename"
#include <filename> or
#include ?filename?
where filename is a standard MSDOS file specifier.
In the latter case (?? delimiters) the file is taken as a
library file, containing only function definitions (not data
declarations) which are compiled only if unresolved (as a function)
from the preceding source text.
12.3 #if - #else - #endif control lines do not nest.
12.4 #line is not implemented.
12.new #list+/#list- causes listing to be turned on/off.
14.3 Arrays must be declared as 1-dimensional.
15. Constants must be:
a float constant;
a simple number, optionally preceded by !, after #if;
numbers or sizeof expressions, with arithmetic operators
* % / + - >> << & ^ | ( ), for array subscripts, or numbers or
character constants with arithmetic operators for case values;
as case constants, or strings (taken by address) or &variables
or &struct.elements, + or - a constant offset (scaled as to
type), for inline or initialiser constants.
17. Anachronisms are not recognised.
Low-Level Interface
-------------------
SMC compiles code using BX as the primary arithmetic register and DI as
the secondary register, as shown in Berry and Meekings 'A Book on C'. Other
registers may be used, but only incidentally, except for floats which use
registers BX, CX and DX. Only the segment registers and stack need be
preserved on executing machine code within a SMC program. Functions return
values in the BX register, or BX, CX and DX for floats.
Note that only the inline statement inserts code into the code segment,
for direct execution. To execute code in the data segment (within
a literal or char array) use functions asm() or mcrun() in SMIO.LIB.
Memory map:
Code segment. Bytes 0x101/102 define the offset to the data segment.
The SMC execution module and runtime functions are
resident from CSEG address 0x100 to (approximately)
0x680 with floats, or 0x320 without. The program code
follows, immediately followed by the data segment.
Data segment. Bytes 0x100/101 point to the end of the literals - ie.
the start of the initialisers (and heap).
Bytes 0x102/103 point to the lowest static data address.
Bytes 0x104/105 point to the (CSEG) address of main().
The data segment contains all areas other than program
code: the literals start at 0x110, then the initialisers
(overwritten by the heap during execution) then the
static data locations and the stack.
Any address (except NULL) below 0x100 is invalid, and
may wreck the program, as it points to program code.
Statics are allocated downwards from 0x9FFC, and
top of stack is at 0xAF40 (or in each case the
values fixed by the command line), though main()
arguments access just above the top of actual stack.
Command line words (and the array argv) are stored
between actual top of stack and the top of the declared
stack area, normally from 0xAF60 to 0xAFF0.
The SMC execution module resets the memory allocated
by MSDOS on commencing execution, to include the program
code and all DSEG areas, ending just above the declared
stack area, normally at DSEG offset 0xB000.
Extra segment. The SMC.COM compiler requests allocation of 0xE000
bytes of memory from MSDOS on commencement, for
storage of intermediate code, and will halt if this
is not available.
Syntax Error Numbers
--------------------
10 Unbalanced function { }'s.
12 Illegal number/constant value.
14 Illegal sizeof argument.
16 Macro definition error.
18 Undefined control line.
20 Missing/illegal storage class/type specifier.
22 Cannot store this value.
24 Expression stacks error.
26 Unrecognised type specifier/identifier.
28 Unrecognised aggregate element.
30 Expecting a numeric value.
32 Cannot read element declaration.
34 Aggregate has no elements.
36 Aggregate and tag types differ.
38 Aggregate definition syntax.
40 Illegal array specifier.
42 Expecting declarator name.
44 Expecting function argument.
46 Too many array specifiers.
48 Illegal array size specifier.
50 Expecting a primary.
52 Not in the argument list.
54 Expecting a type specifier.
56 Expecting { and function body.
58 Premature EOF.
60 Unbalanced loop terminator.
62 Expecting "while" after "do".
64 Expecting ":" after "?".
66 Expecting label name.
68 No for/do/while loop pending.
70 Cannot initialise variable as pointer.
72 Cannot initialise char array here.
74 Cannot initialise this identifier.
76 Initialiser exceeds char width.
78 Initialiser exceeds declared size.
80 Cannot read initialiser data.
Uncorrected minor errors
------------------------
1. Any expression yielding a struct or union type at precedence level
/ * % or below will give an error. Thus (*a).el will give error where
a is a struct pointer - so replace this by a->el.
2. Function printf in SMIO.LIB, if used to print a float with specifier
'g', left justified and with 0 padding (right), will print blanks in
place of non-significant zeros after the decimal point.
Examples and Compilation
--------------------------
See the source files SMC, SMINT, SMDEFS, SMIO.H and SMIO.LIB, and the
text editor TCED, for examples using (and the definitive statement of) SMC.
SMC may be recompiled by locating the five files above, together with
the object program SMC.COM, on the default drive and executing
'SMC SMC NEW.COM' as the command line. NEW.COM will be an exact copy
of SMC.COM after compilation.
A normal C source program (say TEST) may be compiled by executing
'SMC TEST TEST.COM' as the command line, then may be executed immediately
by 'TEST'. However note that the SMC IO header and library files are
SMIO.H and SMIO.LIB - not STDIO.H and STDIO.LIB, though you can of course
rename them if you wish.
During compilation (with listing on) the compiler displays a report line
[aaaa/bbbb/cccc] after each function, where aaaa is the current CSEG
hex address, bbbb is the DSEG literals address, and cccc is the next
(descending) static data allocation address. SMC also gives an address
report at the end of each compilation.
Note that file SMFPS.LIB contains the floating point functions, and this
file should be #included before SMIO.LIB in any program using these
functions, or using printf() specifiers e, f or g. Files SMIO.H and SMIO.LIB
contain no floating point operators, and may be used with command line
option -F for applications using 16 bit arithmetic only.
Functions scanf, fscanf and sscanf are given in file SCANF, but are not
included in file SMIO.LIB. If you wish to include them in SMIO.LIB they
should be taken in as the first functions, at the start of the file.
Acknowledgements and Caution
----------------------------
The author gives grateful acknowledgement to Kernighan and Ritchie, Ron Cain
and Berry and Meekings, whose works (so far as contributing to the concept or
the source code of SMC) he has (he hopes correctly) assumed now to be in the
public domain. The author also wishes to acknowledge the ever continuing
freshness, grace and power of the C Programming Language.
Certain names and works referred to herein (MSDOS, Amstrad etc.) of course
are, and will remain, proprietary.
The author hereby assigns and releases SMC into the public domain, and
hopes that users will have as much pleasure from it as him.
That said, the author can accept no responsibility or legal liability
for any loss or damage (direct, indirect or consequential) resulting
from any defect in or use of SMC.
T. J. M. Caton
34, Park Road,
Godalming, Surrey.
10.1.88
-----------------
*/